package com.tqjc.system.C24012.core.config.websocket;

import com.tqjc.system.C24012.common.constant.SystemConstants;
import com.tqjc.system.common.constant.GlobalConstant;
import com.tqjc.system.core.util.RequestUtil;

import javax.servlet.http.HttpServletRequest;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import java.util.Map;

/**
 * @Author: 86195
 * @CreateTime: 2024-06-28  14:43
 * @Description: TODO
 * @Version: 1.0
 */
public class WebSocketConfigurator extends ServerEndpointConfig.Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        Map<String, Object> userProperties = sec.getUserProperties();
        HttpServletRequest httpServletRequest = RequestUtil.getRequest();
        if(httpServletRequest != null){
            userProperties.put(SystemConstants.STRING_IP,httpServletRequest.getRemoteHost());
        }
    }
}
